package school.model.dao;

import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import school.domain.School;

@Repository
public class SchoolDAOImpl implements SchoolDAO{

	@Autowired
	private SqlSessionTemplate sqlSession;

	@Override
	public int insertSchool(School school) {
		
		return sqlSession.insert(makeSqlId("insertSchool"), school);
	}

	@Override
	public int updateSchool(School school) {
		
		return sqlSession.update(makeSqlId("updateSchool"), school);
	}

	@Override
	public int deleteSchoolById(String schoolId) {
		
		return sqlSession.update(makeSqlId("deleteSchoolById"), schoolId);
	}

	@Override
	public School selectSchoolById(int schoolId) {
		
		return sqlSession.selectOne(makeSqlId("selectSchoolById"), schoolId);
	}

	@Override
	public List<School> selectSchoolList() {
		
		return sqlSession.selectList(makeSqlId("selectSchoolList"));
	}

	@Override
	public List<School> selectSchoolByName(String schoolName) {
		
		return sqlSession.selectList(makeSqlId("selectSchoolByName"), schoolName);
	}

	@Override
	public List<School> selectSchoolByAddress(String schoolAddress) {
		
		return sqlSession.selectList(makeSqlId("selectSchoolByAddress"), schoolAddress);
	}
	
	private String makeSqlId(String id){
		return "school.manager.school."+id;
	}
	
}
